package bawei.com.model;


import android.content.Context;


import android.content.DialogInterface;

import android.content.Intent;
import android.net.ConnectivityManager;


import android.net.NetworkInfo;



import android.support.v7.app.AlertDialog;
import android.widget.Toast;



import bawei.com.bilibili.MyAppliction;

/**
 * 类描述:判断网络
 * 作者：cwm
 * 时间:2017/3/17 18:18
 * 邮箱:18310832074@163.com
 */

public class NetWorkUtil {


    public static boolean isNET(){

        //获取网络管理者
        ConnectivityManager manager = (ConnectivityManager) MyAppliction.context.getSystemService(MyAppliction.context.CONNECTIVITY_SERVICE);
        //获取网络信息
        NetworkInfo info = manager.getActiveNetworkInfo();
        //网络信息不为空且网络可用
        if(info!=null&&info.isAvailable()){
            //获取网络名称
            String name = info.getTypeName();
            //判断当前网络类型
            if (info.getType()==ConnectivityManager.TYPE_WIFI){
                Toast.makeText(MyAppliction.context,"当前正在使用无线网络",Toast.LENGTH_LONG).show();
            }else
            if(info.getType()==ConnectivityManager.TYPE_MOBILE){
                Toast.makeText(MyAppliction.context,"当前正在使用2G 3G 4G网络",Toast.LENGTH_LONG).show();
            }
                return true;
        }else{
            Toast.makeText(MyAppliction.context,"当前网络不可用",Toast.LENGTH_LONG).show();
            return false;
        }

    }


}
